//
//  HomePageWeb.m
//  ZAKER
//
//  Created by dllo on 15/9/5.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "HomePageWeb.h"


@interface HomePageWeb ()<UIWebViewDelegate>

@property (nonatomic, retain) NSDictionary *dic;
@property (nonatomic, retain) MBProgressHUD *mb;

@end

@implementation HomePageWeb

-(void)dealloc
{
    
    [_mb release];
    [_dic release];
    [_url release];
    [_deoId release];
    
    [super dealloc];
    
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIWindow *window = [[[UIApplication sharedApplication]delegate]window];
    self.mb = [[[MBProgressHUD alloc] initWithWindow:window] autorelease];
    _mb.labelText = @"正在加载";
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)8 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        
        if (_mb != nil) {
            [_mb removeFromSuperview];
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"数据加载失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert  show];
            [alert release];
        }
    });
    
    [window addSubview:_mb];
    [_mb show:YES];
    
    [MyAFNetworking GetWithURL:self.url dic:nil data:^(id responsder) {
        
        self.dic = responsder[_deoId];
        [self createWebView];
        [_mb hide:YES];
        _mb  = nil;
//        [_mb release];
        
    }];
}

#pragma mark - 创建webView以及实现协议方法

- (void)createWebView
{

    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49)];
    [web loadHTMLString:self.dic[@"body"] baseURL:nil];
    [self.view addSubview:web];
    web.delegate = self;
    [web release];
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_mb hide:YES];
}

- (void)didReceiveMemoryWarning
{
    
    [super didReceiveMemoryWarning];
   
}

@end
